<?php

class Controller extends CController
{

    public $layout = 'layout';
    public $menu = array();
    public $breadcrumbs = array();

    public function filters()
    {
	return array(
	    'accessControl',
	);
    }

    public function accessRules()
    {
	$controllerId = $this->getId();
	if (!$controllerId) {
	    return array();
	}
	$acl = Yii::app()->params['acl'];
	if (!$acl) {
	    return array();
	}
	if (isset($acl[$controllerId])) {
	    return $acl[$controllerId];
	}
	return array();
    }

    protected function beforeRender($view)
    {
	if (parent::beforeRender($view)) {
	    SeoManager::getInstance()->render();
	}
	return true;
    }

    protected function beforeAction($action)
    {
	if (parent::beforeAction($action)) {
	    $seoModel = FactoryService::get('seo')->getByControllerAndAction($this->getId(), $this->getAction()->getId());
	    if ($seoModel) {
		SeoManager::getInstance()->set(array(
		    'title' => $seoModel->getDbData('title'),
		    'description' => $seoModel->getDbData('description'),
		    'keywords' => $seoModel->getDbData('keywords'),
			)
		);
	    }
	}

	return true;
    }

    public function processOutput($output)
    {
	if (isset($_GET['debug']) && $_GET['debug'] = 'flush') {
	    CacheManager::getCache('memcache')->flush();
	}	
	return parent::processOutput($output);
	$output = parent::processOutput($output);
	$output = preg_replace(array('/>\s+</im'), array('><'), $output);
	return $output;
    }

}